from flask import Flask, request  
  
app = Flask(__name__)  
  
@app.route('/')  
def index():  
    ip_address = request.headers.get('X-Forwarded-For', request.remote_addr)  
    # 如果使用反向代理，'X-Forwarded-For'可能包含多个IP，通常第一个是最原始的客户端IP  
    if ip_address and ',' in ip_address:  
        ip_address = ip_address.split(',')[0]  
    return ip_address  
  
if __name__ == '__main__':  
    app.run(host='0.0.0.0')